Day 7: Securing Linux Systems

Protecting Priv Esc Techniques

chroot Jail

chroot

Encryption

LUKS:

cryptsetup - Front end to LUKS and dm-crypt.

shred - Used to overwrite a drive with random data

Network Security Best Practices

Enable SSL/TLS on all web server

Configure SSH to disable root access

Deny unknown hosts

Change default ports

Enable auditd service


Identity and Access Management

SSH:

ssh-keygen (local machine)
ssh-copy-id (copy public key to remote machine)

ssh-add - Add private keys to ssh agent


PAM

Pluggable Authentication Modules

/etc/pam.d

/etc/securetty:


PKI

  1. Both keys must be from same pair
  2. No one has anyone else's Private Key
  3. Confidentiality encrypts with receivers public key
  4. Digital signatures are created with Sender's Private Key

SELINUX Policies

/etc/selinux

getenforce - Check SELinux enforcing setting
getsebool - Check on/off status
sestatus - Check SELinux stats
sealert - Check SELinux violations

UFW

Firewall management tool used to configure iptables

Become a router: sysctl net.ipv4.ip_forward


System Logs

Tracked by syslogd
Supports remote and local logging

syslog = Everything but authentication messages
messages = Non-critical system events
auth.log = Authentication messages in Debian
secure = Authentication messages in RHEL
kern.log = Kernel messages

rsyslogd = /etc/rsyslog.conf

journalctl

View and query log files created by systemd

Configured in: /etc/systemd/jounrmald.conf

last = Display user logins and logouts

rsync = transfers file differences, not all files


LAB

shred
shred -v --iterations=1 /dev/sda/yada/yada = Overwrite data to erase exisiting data

Securing a drive with LUKS
cryptsetup -v --verify-passphrase luksFormat /dev/sda/yada/yada

Opening drive with cryptsetup
`cryptsetup luksOpen /dev/sda/yada/yada databack

Add encrypted volume to /etc/crypttab and /etc/fstab
bash -c "echo databk /dev/sda/yada/yada none >> /etc/crypttab"

sestatus = Current status of SELinux

Apache
/etc/httpd/conf/httpd.conf = Edit web root

semanage fcontext Apply selinux context to files

Firewalls
firewall-cmd --get-zones = Default zones
firewall-cmd --zone=dmz --list-all = list all dmz zones
firewall-cmd --get-active-zones = Get active zones
firewall-cmd --zone=dmz --add-service=https --permanent
firewall-cmd --zone=dmz --add-port=8843 --permanent
firewall --reload

rsyslog
vim /etc/rsyslog.conf = Configurations for remote logging/rules for logging
sudo systemctl restart rsyslog = Apply changes

journalctl
journalctl -p notice - Filter on notice logs only
journalctl --since "2 hours ago" --until "30 minutes ago"
journalctl -u httpd.service = Filter on apache logs

last
last = Login/logout events
lastb = Login failures
lastlog = Last time a user logged in

rsync
rsync -av /files/to/sync /where/to/sync/them